<template>
  <div class="editForm-wrapper">
    <!-- 设为黑名单dialog-->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="editVisible"
    >
      <el-form
        label-width="127px"
        :rules="dataRule"
        ref="editForm"
        :model="editForm"
      >
        <section>
            <section>
                <el-form-item label="选择原因:" prop="reasonVal"
                              :rules="[
                  {required: true, message:'请选择选择原因', trigger:'change'},
                 ]"
                >
                    <el-select clearable placeholder="请选择" v-model="editForm.reasonVal" @change="showText">
                        <el-option
                            v-for="item in  $dictUtils.getDictList('truckBlackReason')"
                            :key="item.value"
                            :label="item.label"
                            :value="Number(item.value)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="其他原因:" v-if="showTextFlag === true" prop="reason"
                              :rules="[
                  {required: true, message:'请输入其他原因', trigger:'blur'},
                 ]">
                  <el-input type="textarea" v-model="editForm.reason" maxlength="50" show-word-limit></el-input>
                </el-form-item>
            </section>
        </section>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick
          >确定</el-button
        >
        <el-button size="small" @click="close()">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { edit } from '@/api/sys/setting/setting.js'
import { tareWeightReceive, grossWeightReceive } from '@/api/weightingManagent/weight.js'
export default {
  components: {},
  data () {
    return {
      method: '',
      title: '',
      editForm: {
        reason: '',
        reasonVal: ''
      },
      truckCreditDeduct: '',
      editVisible: false,
      detailsVisible: false,
      showTextFlag: false,
      id: '',
      isBlacklist: '',
      dataRule: {
      }
    }
  },
  methods: {
  	handleClose(done) {
		this.$Msg.confirm({
			title:'您确定要关闭吗？',
			content:this.GLOBAL.FORM_CLOSE_TIPS,
			confirmCall:()=>{
				done();
			}
		})
	},
    init (method, id, blacklist) {
      if (method === 'edit') {
        this.editVisible = true
        this.editForm = {
          reason: '',
            reasonVal: ''
        }
        this.id = id
        this.isBlacklist = blacklist
        this.showText()
        this.method = method
        this.$nextTick(() => {
          this.$refs.editForm.resetFields()
        })
        this.title = '填写车辆列入黑名单的原因'
      }
    },
      showText () {
        if (this.editForm.reasonVal === 3) {
            this.showTextFlag = true
        } else {
            this.showTextFlag = false
        }
      },
    close () {
      // this.editForm = {}
      this.editVisible = false
    },
    doSubmit () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
        if (this.editForm.reasonVal !== 3) {
            this.editForm.reason = this.$dictUtils.getDictLabel("receivedReason", this.editForm.reasonVal, "")
        }
        if (this.transProps === 1) {
            this.loading = true
            this.$http({
              url: '/truck/truck/modify-blacklist',
              method: 'post',
              params: {
                'id': id,
                'isBlacklist': blacklist
              }
            }).then(({
              data
            }) => {
              if (data && data.success) {
                this.$message.success(data.message)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
        } else {
            tareWeightReceive({
                truckTrailId: this.truckTrailId,
                operateReason: this.editForm.reason
            }).then(({data}) => {
                if (data.code === '200') {
                    this.$message({
                        message: '撤销成功',
                        type: 'success'
                    })
                    this.$emit('refreshDataList')
                    this.editVisible = false
                }
            })
        }
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .editForm-wrapper{
  .el-form{
    .el-input__inner{}
  }
}
</style>
